/*
 公共数据
 多选控件使用
 */

/*
 * 公共函数
 * 搜索条件/日期控件/日期函数
 * @author polar
 * */
var publicData = {
    //地区
    Area: {

        _html: '', //多选
        _single_html: '', //单选
        _multi_html: [], //三级地区

        //多选
        Multi: function (_dom, _callback) {
            var self = this;
            if (self._html != "") {
                _dom.html(self._html).selectpicker('refresh');
                return;
            }

            var ajaxStr = [];
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_region_list&report_type=1";
            ajaxStr.post_json = {};
            ajaxStr.success = function (result) {
                //成功回调
                self._html = '';
                if (result.data.length != 0) {
                    var _area = result.data[0].list;
                    if (typeof _area != "undefined") {
                        for (var i = 0; i < _area.length; i++) {
                            self._html += '<option value="' + _area[i].code + '">' + (_area[i].name) + '</option>';
                        }
                    }
                }
                _dom.html(self._html).selectpicker('refresh');
            };
            ajaxStr.error = function (result) {
                //失败回调
                var _html = '';
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                var _html = '';
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.ajax(ajaxStr);
        },


        /*
         * 获取下级地区
         *
         * */
        Child: function (parent, seed) {
            var parent_code = parent;
            if(typeof parent === "object"){
                parent_code = parent.val();
            }

            if (parent_code == "" || parent_code == null) {
                seed.html('').selectpicker('refresh');
                return;
            }

            var post_json = {
                condition: {
                    parent_region_code: parent_code,
                    region_code: parent_code
                }
            };

            var ajaxStr = [];
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_region_list";
            ajaxStr.post_json = post_json;
            ajaxStr.async = false;
            ajaxStr.success = function (result) {
                //成功回调
                var _html = '';
                if (typeof seed.attr("multiple") == "undefined") {
                    _html = '<option value="">全部</option>';
                }

                if (result.data.length != 0) {
                    var _area = result.data[0].list;
                    if (typeof _area != "undefined") {
                        for (var i = 0; i < _area.length; i++) {
                            _html += '<option value="' + _area[i].code + '">' + (_area[i].name) + '</option>';
                        }
                    }
                }
                seed.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                seed.html('').selectpicker('refresh');
            };
            ajaxStr.error = function (result) {
                seed.html('').selectpicker('refresh');
            };
            STD.TOOL.getChartData(ajaxStr);
        },

        //根据地区名称获取地区编码
        getCodeByName: function (_name) {
            _name = _name.split(",");
            var result = [];
            var list = this._list;
            for (var i = 0; i < list.length; i++) {
                for (var key in _name) {
                    if (_name[key] == list[i].name) {
                        result.push(list[i].code);
                    }
                }
            }

            return result;
        },

        //根据地区编码获取地区名称
        getNameByCode: function (_code) {
            _code = _code.split(",");
            var result = [];
            var list = this._list;
            for (var i = 0; i < list.length; i++) {
                for (var key in _code) {
                    if (_code[key] == list[i].code) {
                        result.push(list[i].name);
                    }
                }
            }
            return result;
        },

        //单选
        Select: function (_dom) {
            var self = this;
            if (self._single_html != "") {
                _dom.html(self._single_html).selectpicker('refresh');
                return;
            }
            var ajaxStr = {};
            ajaxStr.post_json = {
                "condition": {
                    "node_deep": 1
                }
            };
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_region_list&report_type=1";
            ajaxStr.success = function (result) {
                //成功回调
                if (result.data.length != 0) {
                    var _area = result.data[0].list;
                    var _html = '<option value="">全省</option>';

                    if (typeof _area != "undefined") {
                        for (var i = 0; i < _area.length; i++) {
                            _html += '<option value="' + _area[i].code + '">' + (_area[i].name) + '</option>';
                        }
                        if (_area.length == 1) {
                            _html = '<option value="' + _area[0].code + '">' + (_area[0].name) + '</option>';
                        }
                    }
                }
                self._single_html = _html;
                _dom.html(_html).selectpicker('refresh').trigger('change');
            };
            ajaxStr.error = function (result) {
                //失败回调
                var _html = '';
                _dom.html(_html).selectpicker('refresh').trigger('change');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                var _html = '';
                _dom.html(_html).selectpicker('refresh').trigger('change');
            };

            STD.TOOL.ajax(ajaxStr);
        },

        //获取三级地区
        getMultiLevel: function (parent, child, grandson) {
            var self = this;
            var ajaxStr = [];
            ajaxStr.post_json = {
                "condition": {
                    "node_deep": 3
                }
            };

            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_region_list&report_type=1";
            ajaxStr.async = false;
            ajaxStr.success = function (result) {
                self._multi_html = result.data;
            };
            ajaxStr.error = function (result) {
                //失败回调
                parent.html('').selectpicker('refresh');
                child.html('').selectpicker('refresh');
                grandson.html('').selectpicker('refresh');

            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                parent.html('').selectpicker('refresh');
                child.html('').selectpicker('refresh');
                grandson.html('').selectpicker('refresh');

            };

            if (self._multi_html == "") {
                STD.TOOL.ajax(ajaxStr);
            }

            if (self._multi_html.length > 0) {

                var _area = self._multi_html[0].list;
                if (_area.length > 1) {
                    var _html = '<option value="">全省</option>';
                    for (var i = 0; i < _area.length; i++) {
                        _html += '<option value="' + _area[i].code + '">' + (_area[i].name) + '</option>';
                    }
                    parent.html(_html).selectpicker('refresh');
                    child.html('').selectpicker('refresh');
                    grandson.html('').selectpicker('refresh');
                }

                if (_area.length == 1) {
                    parent.html('<option value="' + _area[0].code + '">' + (_area[0].name) + '</option>').selectpicker('val', _area[0].code).selectpicker('refresh');
                    var child_list = _area[0].list;
                    var child_html = '';

                    if (child_list.length > 1) {
                        child_html = '<option value="">全部</option>';
                        for (var j = 0; j < child_list.length; j++) {
                            child_html += '<option value="' + child_list[j].code + '">' + (child_list[j].name) + '</option>';
                        }
                        child.html(child_html).selectpicker('refresh');
                        grandson.html('').selectpicker('refresh');
                    }

                    if (child_list.length == 1) {
                        child.html('<option value="' + child_list[0].code + '">' + (child_list[0].name) + '</option>').selectpicker('val', child_list[0].code).selectpicker('refresh');
                        var grandson_list = child_list[0].list;
                        var grandson_html = '';

                        if (grandson_list.length > 1) {
                            if (typeof grandson.attr("multiple") == "undefined") {
                                grandson_html = '<option value="">全部</option>';
                            }
                            for (var m = 0; m < grandson_list.length; m++) {
                                grandson_html += '<option value="' + grandson_list[m].code + '">' + (grandson_list[m].name) + '</option>';
                            }
                            grandson.html(grandson_html).selectpicker('refresh');
                        }

                        if (grandson_list.length == 1) {
                            grandson.html('<option value="' + grandson_list[0].code + '">' + (grandson_list[0].name) + '</option>').selectpicker('val', grandson_list[0].code).selectpicker('refresh');
                        }
                    }
                }

                /*地区联动绑定*/
                var parent_event = function () {
                    if (parent.val() == "") {
                        child.html('').selectpicker('refresh');
                        grandson.html('').selectpicker('refresh');
                    }
                    else {
                        publicData.Area.Child(parent, child, true);
                        publicData.Area.Child(child, grandson, true);
                    }
                };
                parent.off("change", parent_event);
                parent.on("change", parent_event);

                var child_event = function () {
                    if (child.val() == "") {
                        grandson.html('').selectpicker('refresh');
                    }
                    else {
                        publicData.Area.Child(child, grandson, true);
                    }
                };
                child.off("change", child_event);
                child.on("change", child_event);
            }
        },

        //获取地图
        getMap: function () {
            var self = this;
            if (!$.isEmptyObject(self.geoMap)) {
                return self.geoMap;
            }
            $.ajax({
                type: "get",
                url: 'nn_api/nn_dispatch.php?func=get_map&platform_id=' + localStorage.platform_id,
                async: false,
                success: function (map) {
                    self.geoMap = map;
                }
            });
            return self.geoMap;
        }
    },

    //版本号
    Version: {

        _version: [],

        //多选
        Multi: function (_dom, _callback) {
            var self = this;
            var _html = '';
            if (self._version != "") {
                for (var i = 0; i < self._version.length; i++) {
                    _html += '<option value="' + self._version[i].apk_version + '">' + self._version[i].version + '</option>';
                }
                _dom.html(_html).selectpicker('refresh');
                return;
            }

            var ajaxStr = [];
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_apk_version_list";
            ajaxStr.post_json = {
                page_num: 1,
                page_size: 9999
            };
            ajaxStr.success = function (result) {
                //成功回调
                self._version = [];

                var _version = result.data;
                self._version = _version;
                for (var i = 0; i < _version.length; i++) {
                    _html += '<option value="' + _version[i].apk_version + '">' + _version[i].version + '</option>';
                }
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.error = function (result) {
                //失败回调
                var _html = '';
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                var _html = '';
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.getChartData(ajaxStr);
        },

        //单选
        Select: function (_dom, _callback) {
            var self = this;
            var ajaxStr = [];
            var _html = "<option value=''></option>";
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_apk_version_list";
            ajaxStr.post_json = {
                page_num: 1,
                page_size: 9999
            };
            ajaxStr.success = function (result) {
                //成功回调
                self._version = [];
                var _version = result.data;
                self._version = _version;
                for (var i = 0; i < _version.length; i++) {
                    _html += "<option value='" + _version[i].apk_version + "'>" + _version[i].version + "</option>";
                }

                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.error = function (result) {
                //失败回调
                var _html = '';
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据\
                var _html = '';
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.getChartData(ajaxStr);
        }
    },

    //运营商
    SP: {

        _sp: [],

        //获取接口数据
        getSP: function (_dom, type) {
            var self = this;
            var _html = '';

            var ajaxStr = [];
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_sp_list";
            ajaxStr.post_json = {};
            ajaxStr.success = function (result) {
                self._sp = result.data;
                //成功回调
                if (type == "1") {
                    self.Multi(_dom);
                } else {
                    self.Select(_dom);
                }
            };
            ajaxStr.error = function (result) {
                //失败回调
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.ajax(ajaxStr);
        },


        //多选
        Multi: function (_dom, _callback) {
            var self = this;
            if (self._sp != "") {
                var _html = '';
                for (var i = 0; i < self._sp.length; i++) {
                    _html += '<option value="' + self._sp[i].nns_sp_id + '">' + self._sp[i].nns_sp_name + '</option>';
                }

                _dom.html(_html).selectpicker('refresh');
            } else {
                self.getSP(_dom, 1);
            }
        },

        //单选
        Select: function (_dom, _callback) {
            var self = this;
            if (self._sp != "") {
                var _html = "<option value=''> 全部</option>";
                for (var i = 0; i < self._sp.length; i++) {
                    _html += '<option value="' + self._sp[i].nns_sp_id + '">' + self._sp[i].nns_sp_name + '</option>';
                }
                _dom.html(_html).selectpicker('refresh');
            } else {
                self.getSP(_dom, 0);
            }
        },

        //根据SP名称获取SP ID
        getIdByName: function (_name) {
            var name = _name.split(",");
            var result = [];
            var liveli = this._sp;
            for (var i = 0; i < liveli.length; i++) {
                for (var key in name) {
                    if (name[key] == liveli[i].nns_sp_name) {
                        result.push(liveli[i].nns_sp_id);
                    }
                }
            }
            return result;
        },

        getNameById: function (_id) {
            if (typeof _id !== 'string') {
                return _id || '';
            }
            var id = _id.split(",");
            var result = [];
            var liveli = this._sp;
            for (var i = 0; i < liveli.length; i++) {
                for (var key in id) {
                    if (id[key] == liveli[i].nns_sp_id) {
                        result.push(liveli[i].nns_sp_name);
                    }
                }
            }
            if (result.length < 1) {
                result = id;
            }
            return result;
        }
    },

    //内容提供商
    CP: {

        _cp: [],


        //获取接口数据
        getCP: function (_dom, type) {
            var self = this;
            var _html = '';
            var ajaxStr = [];
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_cp_list";
            ajaxStr.post_json = {};
            ajaxStr.success = function (result) {
                self._cp = result.data;
                //成功回调
                if (type == "1") {
                    self.Multi(_dom);
                } else {
                    self.Select();
                }
            };
            ajaxStr.error = function (result) {
                //失败回调
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.ajax(ajaxStr);
        },

        //多选
        Multi: function (_dom, _callback) {
            var self = this;
            if (self._cp != "") {
                var _html = '';
                for (var i = 0; i < self._cp.length; i++) {
                    _html += '<option value="' + self._cp[i].cp_name + '">' + self._cp[i].cp_name + '</option>';

                }

                _dom.html(_html).selectpicker('refresh');
            } else {
                self.getCP(_dom, 1);
            }
        },

        //根据CP名称获取ID
        getIdByName: function (_name) {
            var name = _name.split(",");
            var result = [];
            var liveli = this._cp;
            for (var i = 0; i < liveli.length; i++) {
                for (var key in name) {
                    if (name[key] == liveli[i].cp_name) {
                        result.push(liveli[i].cp_id);
                    }
                }
            }
            return result;
        },

        getNameById: function (_id) {
            var list = this._cp;
            var result = [];
            for (i = 0; i < list.length; i++) {
                if (_id == list[i].cp_id) {
                    result.push(list[i].cp_name);
                }
            }
            return result;
        }
    },

    //终端类型
    Client: {
        _code: [],
        _name: [],
        //多选
        Multi: function (_dom, _callback) {
            var self = this;
            self._code = [];
            self._name = [];
            var client_json ={"stb":"\u673a\u9876\u76d2","pc":"\u7535\u8111","pad":"\u5e73\u677f","phone":"\u624b\u673a"};
            var _html = '';
            for (var key in client_json) {
                self._code.push(key);
                var _name = client_json[key];
                self._name.push(_name);
                _html += '<option value="' + key + '">' + _name + '</option>';
            }

            _dom.html(_html).selectpicker('refresh');
        },

        //单选
        Select: function (_dom, _callback) {
            //TODO
        },

        //根据终端名称获取终端编码
        getCodeByClient: function (_typename) {
            var self = this;
            var type_arr = _typename.split(",");
            var type = [];
            var name = self._name;
            var code = self._code;
            for (var n = 0; n < type_arr.length; n++) {
                for (var m = 0; m < name.length; m++) {
                    if (type_arr[n] == name[m]) {
                        type.push(code[m]);
                    }
                }
            }
            return type;
        },

        //根据终端编码获取终端名称
        getNameByCode: function (code) {
            var client_json ={"stb":"\u673a\u9876\u76d2","pc":"\u7535\u8111","pad":"\u5e73\u677f","phone":"\u624b\u673a"};
            var result = [];
            for (var key in client_json) {
                if (key == code.toLowerCase()) {
                    result.push(client_json[key]);
                }
            }
            return result;
        }
    },

    //清晰度
    Definition: {

        _level: {"4k":"4K","sd":"\u8d85\u6e05","hd":"\u9ad8\u6e05","std":"\u6807\u6e05","low":"\u6d41\u7545","other":"\u5176\u5b83"},
        //多选
        Multi: function (_dom, _callback) {
            var self = this;
            var _html = '';
            for (var key in self._level) {
                _html += '<option value="' + key + '">' + self._level[key] + '</option>';
            }

            _dom.html(_html).selectpicker('refresh');
        },

        //单选
        Select: function (_dom, _callback) {
            //TODO
        },

        //根据清晰度名称获取清晰度编码
        getCodeByDefini: function (_defininame) {
            var self = this;
            var definition_arr = _defininame.split(",");
            var definition = [];
            for (var n = 0; n < definition_arr.length; n++) {
                for (var key in self._level) {
                    if (self._level[key] == definition_arr[n]) {
                        definition.push(key);
                    }
                }
            }
            return definition;
        },

        //根据接口返回的清晰度编码显示名称
        getName: function (_code) {
            var self = this;
            var data = [];
            for (var i = 0; i < _code.length; i++) {
                var str = _code[i].toLowerCase();
                var val = self._level[str];
                if (str == '') {
                    val = '其它';
                }
                if (val == "undefined") {
                    val = str;
                }
                data.push(val);
            }
            return data;
        }
    },

    //节点
    Node: {
        //多选
        Multi: function (_dom, _callback) {
            var ajaxStr = [];
            var _html = '<option value=""></option>';
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_node_list";
            ajaxStr.post_json = {};
            ajaxStr.success = function (result) {
                //成功回调
                var _node = result.data;
                for (var i = 0; i < _node.length; i++) {
                    _html += '<option value="' + _node[i].node_id + '">' + _node[i].node_name + '</option>';
                }

                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.error = function (result) {
                //失败回调
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.getChartData(ajaxStr);
        }
    },

    //频道
    Channel: {
        _liveli: [], //所有元素

        //多选
        Multi: function (_dom, _callback) {
            var ajaxStr = {};
            var self = this;
            var _html = '';
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_live_list";
            ajaxStr.post_json = {};
            ajaxStr.success = function (result) {
                //成功回调
                self._liveli = [];
                var _live = result.data;
                for (var i = 0; i < _live.length; i++) {
                    self._liveli.push(_live[i]);
                    _html += '<option value="' + _live[i].live_id + '">' + _live[i].live_name + '</option>';
                }

                _dom.html(_html).selectpicker('refresh');

            };
            ajaxStr.error = function (result) {
                //失败回调
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.getChartData(ajaxStr);
        },

        //单选
        Select: function (_dom, _callback) {
            var ajaxStr = {};
            var _html = '<option value=""></option>';
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_live_list";
            ajaxStr.post_json = {};
            ajaxStr.success = function (result) {
                //成功回调
                var _live = result.data;
                for (var i = 0; i < _live.length; i++) {
                    _html += '<option value="' + _live[i].live_id + '">' + _live[i].live_name + '</option>';
                }

                _dom.html(_html).selectpicker('refresh');

            };
            ajaxStr.error = function (result) {
                //失败回调
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.getChartData(ajaxStr);
        },

        //根据频道名称获取频道ID
        getIdByLivena: function (_name) {
            _name = _name.split(",");
            var result = [];
            var liveli = this._liveli;
            for (var i = 0; i < liveli.length; i++) {
                for (var key in _name) {
                    if (_name[key] == liveli[i].live_name) {
                        result.push(liveli[i].live_id);
                    }
                }
            }
            return result;
        },

        //根据ID获取名称
        getNameByID: function (id) {
            var liveli = this._liveli;
            for (var i = 0; i < liveli.length; i++) {
                if (liveli[i].live_id == id) {
                    return liveli[i].live_name;
                }
            }
            return id;
        }
    },

    //内容类型
    Content_type: {
        _types: [], //所有元素

        //多选
        Multi: function (_dom, _callback) {
            var ajaxStr = {};
            var self = this;
            var _html = '';
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_content_type_list";
            ajaxStr.post_json = {};
            ajaxStr.success = function (result) {
                //成功回调
                self._types = [];
                var _data = result.data;
                for (var i = 0; i < _data.length; i++) {
                    self._types.push(_data[i]);
                    _html += '<option value="' + _data[i].nns_view_type + '">' + _data[i].nns_view_type + '</option>';
                }

                _dom.html(_html).selectpicker('refresh');

            };
            ajaxStr.error = function (result) {
                //失败回调
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.getChartData(ajaxStr);
        }
    },

    //页面列表
    Client_page: {
        _pageli: [], //所有元素
        _pagena: [], //页面名称
        _pageid: [], //页面ID

        //多选
        Multi: function (_dom, _callback, init) {
            var ajaxStr = [];
            var self = this;
            var _html = "";
            if (init == "") {
                //如果需要默认选中第一项，init：空字符串
                _html = "";
            }

            var platform_id = localStorage.platform_id;
            var post_json = {
                "condition": {
                    "platform_id": platform_id
                }
            };
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_page&action=get_list";
            ajaxStr.post_json = post_json;
            ajaxStr.success = function (result) {
                //成功回调
                var _page = result.data;
                self._pageli = [];
                for (var i = 0; i < _page.length; i++) {
                    self._pageli.push(_page[i]);
                    self._pageid.push(_page[i].nns_page_id);
                    self._pagena.push(_page[i].nns_page_name);
                    _html += "<option value='" + _page[i].nns_page_id + "'>" + _page[i].nns_page_name + "(" + _page[i].nns_page_id + ")</option>";
                }

                _dom.html(_html).selectpicker('refresh');

                if (_callback) {
                    _callback();
                }

            };
            ajaxStr.error = function (result) {
                //失败回调
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.ajaxNoPlatform(ajaxStr);
        },
        //单选
        Select: function (_dom, _callback, init) {
            var ajaxStr = [];
            var self = this;
            var _html = "<option value=''></option>";
            if (init == "") {
                //如果需要默认选中第一项，init：空字符串
                _html = "";
            }
            var platform_id = localStorage.platform_id;
            var post_json = {
                "condition": {
                    "platform_id": platform_id,
                }
            };
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_page&action=get_list";
            ajaxStr.post_json = post_json;
            ajaxStr.success = function (result) {
                //成功回调
                var _page = result.data;
                self._pageli = [];
                for (var i = 0; i < _page.length; i++) {
                    self._pageli.push(_page[i]);
                    self._pageid.push(_page[i].nns_page_id);
                    self._pagena.push(_page[i].nns_page_name);
                    _html += "<option value='" + _page[i].nns_page_id + "'>" + _page[i].nns_page_name + "(" + _page[i].nns_page_id + ")</option>";
                }

                _dom.html(_html).selectpicker('refresh');

                if (_callback) {
                    _callback();
                }

            };
            ajaxStr.error = function (result) {
                //失败回调
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.ajaxNoPlatform(ajaxStr);
        },

        //根据页面ID获取名称
        getNameByCode: function (page_id) {
            page_id = page_id.split(",");
            var result = [];
            var list = this._pageli;
            for (var i = 0; i < list.length; i++) {
                for (var key in page_id) {
                    if (page_id[key] == list[i].nns_page_id) {
                        result.push(list[i].nns_page_name);
                    }
                }
            }
            return result;
        },

        //返回页面列表
        getPageList: function () {
            return this._pageli;
        }
    },

    //营业区
    Business_hall: {

        _list: [], //所有元素

        //多选
        Multi: function (_dom, area_code, _callback) {
            var ajaxStr = [];
            var self = this;
            var platform_id = localStorage.platform_id;
            var post_json = {
                "condition": {
                    "platform_id": platform_id,
                    "area_code": (area_code != null) ? area_code.join(',') : '',
                }
            };
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_business_list";
            ajaxStr.post_json = post_json;
            ajaxStr.success = function (result) {
                //成功回调
                self._list = [];
                if (result.data.length != 0) {
                    var data = result.data;
                    var _html = '';
                    for (var i = 0; i < data.length; i++) {
                        self._list.push(data[i]);
                        _html += '<option value="' + data[i].nns_business_id + '">' + data[i].nns_business_name + '</option>';
                    }
                }
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.error = function (result) {
                //失败回调
                var _html = '<option value=""></option>';
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                var _html = '<option value=""></option>';
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.ajaxNoPlatform(ajaxStr);
        },

        //单选
        Select: function (_dom, area_code, _callback) {
            var ajaxStr = [];
            var self = this;
            var platform_id = localStorage.platform_id;
            var post_json = {
                "condition": {
                    "platform_id": platform_id,
                    "area_code": area_code
                }
            };
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_business_list";
            ajaxStr.post_json = post_json;
            ajaxStr.success = function (result) {
                //成功回调
                self._list = [];
                if (result.data.length != 0) {
                    var data = result.data;
                    var _html = '<option value=""></option>';
                    for (var i = 0; i < data.length; i++) {
                        self._list.push(data[i]);
                        _html += '<option value="' + data[i].nns_business_id + '">' + data[i].nns_business_name + '</option>';
                    }
                }
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.error = function (result) {
                //失败回调
                var _html = '<option value=""></option>';
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                var _html = '<option value=""></option>';
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.ajaxNoPlatform(ajaxStr);
        },

        //根据营业区名称获取id
        getCodeByName: function (_name) {
            _name = _name.split(",");
            var result = [];
            var list = this._list;
            for (var i = 0; i < list.length; i++) {
                for (var key in _name) {
                    if (_name[key] == list[i].nns_business_name) {
                        result.push(list[i].nns_business_id);
                    }
                }
            }
            return result;
        }
    },

    //媒资包
    Package: {

        _list: [], //所有元素

        //多选
        Multi: function (_dom, _callback) {
            var ajaxStr = {};
            var self = this;
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_package_list";
            ajaxStr.post_json = {};
            ajaxStr.success = function (result) {
                //成功回调
                self._list = [];
                if (result.data.length != 0) {
                    var data = result.data;
                    var _html = '';
                    for (var i = 0; i < data.length; i++) {
                        self._list.push(data[i]);
                        _html += '<option value="' + data[i].package_id + '">' + data[i].package_name + '</option>';
                    }
                }
                _dom.html(_html).selectpicker('refresh');

                if (_callback) {
                    _callback();
                }
            };
            ajaxStr.error = function (result) {
                //失败回调
                var _html = '<option value=""></option>';
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                var _html = '<option value=""></option>';
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.getChartData(ajaxStr);
        },

        //单选
        Select: function (_dom, _callback) {
            var ajaxStr = [];
            var self = this;
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_package_list";
            ajaxStr.post_json = {};
            ajaxStr.success = function (result) {
                //成功回调
                self._list = [];
                if (result.data.length != 0) {
                    var data = result.data;
                    var _html = '<option value=""></option>';
                    for (var i = 0; i < data.length; i++) {
                        _html += '<option value="' + data[i].package_id + '">' + data[i].package_name + '</option>';
                    }
                }
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.error = function (result) {
                //失败回调
                var _html = '<option value=""></option>';
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                var _html = '<option value=""></option>';
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.getChartData(ajaxStr);
        },

        //栏目
        Child: function (parent, seed) {
            if ($(parent).val() == "") {
                $(seed).html('').selectpicker('refresh');
                return;
            }

            var post_json = {
                condition: {
                    package_id: $(parent).val()
                }
            };

            var ajaxStr = {};
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_data&action=get_category_list_by_package_id";
            ajaxStr.post_json = post_json;
            ajaxStr.success = function (result) {
                //成功回调
                var _html = '';
                var _citys = result.data;

                for (var i = 0; i < _citys.length; i++) {
                    _html += "<option value=\"" + _citys[i].category_id + "\">" + _citys[i].category_name + "</option>";
                }
                seed.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                seed.html('').selectpicker('refresh');
            };
            ajaxStr.error = function (result) {
                seed.html('').selectpicker('refresh');
            };
            STD.TOOL.getChartData(ajaxStr);
        }
    },

    //详单配置
    Details: {
        details: {},

        //多选
        getDetails: function (action) {
            var self = this;

            var ajaxStr = {};
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_detail_config";
            ajaxStr.post_json = {};
            ajaxStr.async = false;
            ajaxStr.success = function (result) {
                //成功回调
                self.details = result.data;
            };

            if ($.isEmptyObject(self.details)) {
                STD.TOOL.getChartData(ajaxStr);
            }
            if (!$.isEmptyObject(self.details)) {
                if (typeof action != "undefined") {
                    return self.details[action];
                }
                return self.details;
            }
        }
    },

    //重置条件
    Reset: {

        Set: function (objs) {
            //清空当前可见页面的可见输入框(隐藏状态的不会被重置)
            $(".page-content > div:visible input[type='text']:visible").val("");
            $(".page-content > div:visible .public-select").selectpicker("val", "");
        }
    },

    //数组排序
    // 将用户选择的指标排在第一位
    firstArray: {
        Set: function (arr, firstStr) {
            for (var i = 0; i < arr.length; i++) {
                if (arr[i] == firstStr) {
                    arr.splice(i, 1);
                }
            }
            arr.unshift(firstStr);
        }
    },

    //获取浏览器
    browser: {
        getBro: function () {
            var bro = '';
            var nav = navigator.userAgent.toLowerCase();
            if (!!window.ActiveXObject || "ActiveXObject" in window) {
                return "IE";
            }
            if (isFirefox = nav.indexOf("firefox") > 0) {
                return "Firefox";
            }
            if (isChrome = nav.indexOf("chrome") > 0 && window.chrome) {
                return "Chrome";
            }
            if (isSafari = nav.indexOf("safari") > 0 && nav.indexOf("version") > 0) {
                return "Safari";
            }
            if (isCamino = nav.indexOf("camino") > 0) {
                return "Camino";
            }
            if (window.opr != undefined) {
                return "Opera";
            }
            return bro;
        }
    },

    //验证输入框
    Verify: {
        inputVerify: function (val, type, name, isNull) {
            if (!isNull && val == "") {
                return name + "：不能为空";
            }

            if (val == "") {
                return true;
            }

            if (type == "url" || type == "string") {
                return true;
            }

            var data = {
                /*6-18位数字字母下划线组合,以字母开头*/
                "userName": {
                    "regex": /^[a-zA-Z][\w]{5,17}$/,
                    "alertText": "6~18个字符，可使用字母、数字、下划线，需以字母开头",
                    "alertType": "1"
                },
                /*6-18位数字字母下划线组合,以字母或者数字开头*/
                "newUserName": {
                    "regex": /^[a-zA-Z0-9][\w]{0,32}$/,
                    "alertText": "可使用字母、数字、下划线，需以字母或者数字开头",
                    "alertType": "1"
                },
                /*6-16位数字字母组合,区分大小写*/
                "password": {
                    "regex": /^[a-zA-Z\d]{6,16}$/,
                    "alertText": "6~16个字母和数字组合，区分大小写",
                    "alertType": "1"
                },
                "id": {
                    "regex": /^[0-9a-zA-Z_\-\.\/]+$/,
                    "alertText": "字母、数字、横杠'-'、下划线'_'、小数点'.',斜线'/'",
                    "alertType": "1"
                },
                "number": {
                    "regex": /^\d+(\.\d+)?$/,
                    "alertText": "整数，小数",
                    "alertType": "1"
                },
                "phone": {
                    "regex": /^1[0-9]{10}$/,
                    "alertText": "正确的手机号",
                    "alertType": "1"
                },
                "int": {
                    "regex": /^[0-9]+$/,
                    "alertText": "整数",
                    "alertType": "1"
                },
                "string": {
                    "regex": /^[a-zA-Z0-9_\u4E00-\u9FA5\.\/\-\+\，\,\?\？\:\：\@\。\ \[\]\(\)\（\）]+$/,
                    "alertText": "字母、数字、中文、横杠'-'、斜杠'/'、加号'+'、下划线'_'、小数点'.'、逗号、问号、冒号 、@、句号、空格、[]",
                    "alertType": "1"
                },
                "contentPath": {
                    "regex": /^[a-zA-Z0-9_\u4E00-\u9FA5\.\-\@\(\)\（\）\：\:\!\&\！\*\|\/\\\?\？\。]+$/,
                    "alertText": "无效的路径",
                    "alertType": "2"
                },
                "email": {
                    "regex": /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,
                    "alertText": "无效的邮件地址",
                    "alertType": "2"
                },
                "ip": {
                    "regex": /^[0-9a-zA-Z\[\]\.\:\/\%]+$/,
                    "alertText": "字母、数字、冒号、[]括号、小数点、/、%",
                    "alertType": "1"
                },
                "netDomain": {
                    "regex": /^[0-9a-zA-Z\.\-\_]+$/,
                    "alertText": "字母、数字、小数点'.'、横杠'-'、下划线'_'",
                    "alertType": "1"
                },
                "url": {
                    "regex": /^((https?|http):\/\/)?(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i,
                    "alertText": "无效的网址",
                    "alertType": "2"
                },
                "onlyLetter": {
                    "regex": /^[a-zA-Z]+$/,
                    "alertText": "英文字母",
                    "alertType": "1"
                },
                "onlyLetterNumber": {
                    "regex": /^[0-9a-zA-Z]+$/,
                    "alertText": "数字与英文字母",
                    "alertType": "1"
                },
                "cdnexFileType": {
                    "regex": /^[0-9a-zA-Z_\(\)\*]+$/,
                    "alertText": "字母、数字、下划线'_'、小数点'.'、'*'、（）",
                    "alertType": "1"
                }
            };

            for (var idx in data) {
                if (idx.toLowerCase() == type.toLowerCase()) {
                    var re = data[idx].regex;
                    var result = data[idx].alertText;
                    var alert_type = data[idx].alertType;
                    if (re.test(val)) {
                        return true;
                    } else {
                        if (alert_type == "1") {
                            //alert(name+"：输入框中存在非法字符");
                            return (name + "只能填写：" + result);
                        } else {
                            //针对允许字符较多的校验，每种字符都提示太长，做通用简化提示
                            return (name + "：" + result);
                        }
                        return false;
                    }
                }
            }

            return true;
        }
    },

    //性别处理
    Sex: {
        getSex: function (echart_data) {
            var sex_data = [];
            sex_data.spot = [];
            sex_data.data = [];
            sex_data.data[0] = [];
            sex_data.desc = [];
            sex_data.desc = echart_data.desc;
            var _other = 0;
            for (var i = 0; i < echart_data.spot.length; i++) {
                if (echart_data.spot[i] == '男') {
                    sex_data.spot.push(echart_data.spot[i]);
                    sex_data.data[0].push(echart_data.data[0][i]);
                }
                if (echart_data.spot[i] == '女') {
                    sex_data.spot.push(echart_data.spot[i]);
                    sex_data.data[0].push(echart_data.data[0][i]);
                }
                if (echart_data.spot[i] == '其它' || echart_data.spot[i] == 'm' || echart_data.spot[i] == 'f') {
                    _other += parseInt(echart_data.data[0][i]);
                }
            }
            if (typeof (_other) != "undefined") {
                sex_data.spot.push('其它');
                sex_data.data[0].push(_other);
            }
            return sex_data;
        }
    },

    //推荐算法和内容
    Recommend: {
        filmType: function () {
            var type = {
                '1': '电视剧',
                '2': '综艺',
                '3': '动漫',
                '4': '音乐',
                '5': '纪实',
                '6': '教育',
                '7': '体育',
                '8': '生活',
                '9': '财经',
                '10': '微电影',
                '11': '品牌专区',
                '12': '广告',
                '13': '新闻',
                '14': '资讯',
                '15': '外语节目',
                '16': '青少年',
                '17': '博客',
                '18': '游戏',
                '19': '原创',
                '20': '儿童',
                '21': '公益',
                '22': '微视频',
                '23': '政治',
                '24': '军事',
                '25': '法律',
                '26': '文教卫生体育',
                '27': '文艺',
                '28': '科技人文',
                '29': '其它',
                '30': '舞蹈',
                '31': '三农'
            };
            return type;
        },
        getAlgorithm: function () {
            var algorithm = {
                "per": {
                    "CB": '基于内容推荐',
                    "CF": '协同过滤算法推荐',
                    "POP": '热门内容推荐'
                },
                "sim": {
                    "PERSON": 'Person相关性推荐'
                }
            };
            return algorithm;
        }
    },

    //订单数据
    Order: {
        payChannel: function () {
            var channel = {
                "alipay": "支付宝",
                "weixin_pay": "微信支付",
                "paypal": "贝宝支付",
                "offline": "线下支付",
                "exchange_card": "卡券兑换",
                'boss_pay': "Boss支付"
            };
            return channel;
        },
        orderState: function () {
            var state = {
                '0': "未支付",
                '1': "已支付",
                '2': "取消",
                '3': "过期",
                '4': "已添加临时授权,等待扣款",
                '5': "已退订"
            };
            return state;
        },
        productType: function () {
            var type = {
                "single": "单片",
                "cycle": "集合",
                "combine": "组合",
                "card": "观影券"
            };
            return type;
        }
    },

    //日期控件
    datePlug: {

        //日期范围
        Set: function (ele, params) {
            var div_obj = ele,
                params = $.extend({}, params);
            if (typeof ele == "string") {
                div_obj = $('#' + ele);
            }
            /*日期展开方向*/
            var position = (App.isRTL() ? 'right' : 'left');
            var offset = div_obj.offset();
            if (offset) {
                var left = offset.left;
                if (0 < left && left < 672) {
                    position = 'right';
                }
            }


            if (typeof arr != "undefined" && typeof arr.position != "undefined") {
                position = arr.position;
            }

            if (!jQuery().daterangepicker) {
                return;
            }

            var _dateFormat = "YYYY/MM/DD";
            if(params.timePicker){
                _dateFormat = params.timePicker == "hour" ? "YYYY/MM/DD HH:00" :
                    params.timePicker == "minutes" ? "YYYY/MM/DD HH:mm" :
                        params.timePicker == "seconds" ? "YYYY/MM/DD HH:mm:ss" : _dateFormat;
            }

            var _startDate = moment().subtract('days', 7).format(_dateFormat);
            var _endDate = moment().subtract('days', 1).format(_dateFormat);
            if (ele == "index_search_date") {
                _startDate = moment().subtract('days', 7).format(_dateFormat);
                _endDate = moment().subtract('days', 7).format(_dateFormat);
            }

            if (typeof params != "undefined" && typeof params.start != "undefined" && typeof params.end != "undefined") {
                _startDate = params.start.format(_dateFormat);
                _endDate = params.end.format(_dateFormat);
            }

            /*截止时间*/
            var maxDate = moment();
            if (params && params.maxDate) {
                maxDate = moment().subtract('days', params.maxDate)
            }
            div_obj.daterangepicker({
                startDate: _startDate,
                endDate: _endDate,
                showWeekNumbers: true,//是否显示第几周
                applyClass: 'btn-sm btn-success',
                cancelClass: 'btn-sm btn-default',
                timePicker: !!params.timePicker,
                timePickerSeconds: !!(params.timePicker == 'seconds'),
                "timePicker24Hour": true,
                "ranges": {
                    '今天': [moment(), moment()],
                    '昨天': [moment().subtract('days', 1), moment().subtract('days', 1)],
                    '最近7天': [moment().subtract('days', 7), moment().subtract('days', 1)],
                    '最近30天': [moment().subtract('days', 30), moment().subtract('days', 1)],
                    '本月': [moment().startOf('month'), moment().endOf('month')],
                    '上月': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
                },
                "maxDate": maxDate,
                "format": _dateFormat,
                "locale": {
                    "format": _dateFormat,
                    "separator": " - ",
                    "weekLabel":"周",
                    "applyLabel": "确定",
                    "cancelLabel": "取消",
                    "fromLabel": "开始时间",
                    "toLabel": "结束时间",
                    "customRangeLabel": "选择时间",
                    "daysOfWeek": ["日", "一", "二", "三", "四", "五", "六"],
                    "monthNames": ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
                    "firstDay": 1
                },
                opens: position
            }, function (start, end, label) {
                if (div_obj.attr('data-display-range') != '0') {
                    div_obj.children("span").html(start.format(_dateFormat) + ' - ' + end.format(_dateFormat));
                }
            });

            div_obj.children("span").html(_startDate + ' - ' + _endDate);
        },

        //日期选择，精确到年
        yearPicker: function (ele, params) {
            var div_obj = ele;
            if (typeof ele == "string") {
                div_obj = $('#' + ele);
            }

            if (!jQuery().datepicker) {
                return;
            }

            var _dateFormat = "yyyy";
            var _lang = cookie.get('lang_id');
            var endDate = "2019";
            if (params && params.endDate) {
                endDate = params.endDate;
            }
            div_obj.datepicker({
                rtl: false,
                format: _dateFormat,
                language: _lang,
                todayHighlight: true,
                endDate: endDate,
                startDate: -Infinity,
                autoclose: true,
                startView: "years",
                minViewMode: "years"
            });
            var initDate = params && params.date || new Date();
            div_obj.datepicker('setDate', moment(initDate).format("YYYY"));
        },

        //日期选择，精确到月
        monthPicker: function (ele, params) {
            var div_obj = ele;
            if (typeof ele == "string") {
                div_obj = $('#' + ele);
            }

            if (!jQuery().datepicker) {
                return;
            }

            var _dateFormat = "yyyy/mm";
            var _lang = cookie.get('lang_id');
            var endDate = "2019/05";
            if (params && params.endDate) {
                endDate = params.endDate;
            }

            div_obj.datepicker({
                rtl: false,
                format: _dateFormat,
                language: _lang,
                todayHighlight: true,
                endDate: endDate,
                startDate: -Infinity,
                autoclose: true,
                startView: "months",
                minViewMode: "months"
            });
            var initDate = params && params.date || new Date();
            // moment插件兼容性，moment('2018/01') => invalid, moment('2018-01') => valid
            (typeof initDate === 'string') && (initDate = initDate.replace(/\//g, '-'));
            div_obj.datepicker('setDate', moment(initDate).format("YYYY/MM"));
        },

        //日期选择，精确到天(单选)
        datePicker: function (ele, params) {
            var div_obj = ele;
            if (typeof ele == "string") {
                div_obj = $('#' + ele);
            }

            if (!jQuery().datepicker) {
                return;
            }

            var _dateFormat = "yyyy/mm/dd";
            var _lang = cookie.get('lang_id');
            var endDate = "2019/05/23";
            if (params && params.endDate) {
                endDate = params.endDate;
            }

            div_obj.datepicker({
                rtl: false,
                format: _dateFormat,
                language: _lang,
                todayHighlight: true,
                endDate: endDate,
                startDate: -Infinity,
                autoclose: true
            });
            var initDate = params && params.date || new Date();
            div_obj.datepicker('setDate', moment(initDate).format("YYYY/MM/DD"));
        },

        //日期选择，精确到分钟
        //params.minView:'day',精确到小时
        timePicker: function (ele, params, callback) {
            var div_obj = ele;
            if (typeof ele == "string") {
                div_obj = $('#' + ele);
            }

            if (!jQuery().datetimepicker) {
                return;
            }
            var minView = 'hour';
            if (params && params.minView) {
                minView = params.minView;
            }

            var _dateFormat = "yyyy/mm/dd hh:ii";
            var _lang = cookie.get('lang_id');

            div_obj.datetimepicker({
                autoclose: true,
                isRTL: App.isRTL(),
                language: _lang,
                format: _dateFormat,
                minView: minView,
                todayHighlight: true,
                endDate: new Date()
            }).on('hide', function (ev) {
                if (callback) {
                    callback(ev);
                }
            });
        },

        //日期选择，精确到周，下拉框
        weekPicker: function (ele) {
            var div_obj = ele;
            if (typeof ele == "string") {
                div_obj = $('#' + ele);
            }
            var weekStr = '';

            //今年第一天
            var today = new Date();
            var firstDay = new Date(today.getFullYear(), 0, 1);
            var firstWeek = firstDay.getDay();
            var numDay = (firstWeek != 0) ? (firstWeek - 1) : 6;
            //获取第一周周一
            firstDay = firstDay.getFullYear() + "/" + (firstDay.getMonth() + 1) + "/" + firstDay.getDate();
            var monday = publicData.Date.addDay(firstDay, numDay, false);
            //当前第几周
            var weeks = Math.ceil(Math.ceil((today.getTime() - new Date(monday).getTime()) / 86400000) / 7);

            //获取每周日期
            for (var i = weeks; i > 0; i--) {
                var day = publicData.Date.addDay(monday, (i - 1) * 7)
                var val = day + '-' + publicData.Date.addDay(day, 6);
                var text = i + '周(' + day.substr(4) + "-" + publicData.Date.addDay(day, 6).substr(4) + ')';

                if (i != weeks) {
                    weekStr += '<option value="' + val + '">' + text + '</option>';
                } else {
                    weekStr += ' <option value="' + val + '" data-content="' + text + ' <span class=\'label lable-sm label-success\'>本周 </span>"></option>'
                }
            }
            div_obj.html(weekStr).selectpicker('refresh');
        },

        //选择周
        weekPicker2: function (ele, params) {
            var div_obj = ele;
            if (typeof ele == "string") {
                div_obj = $('#' + ele);
            }

            if (!jQuery().datepicker) {
                return;
            }

            var _dateFormat = "yyyy/mm/dd";
            var _lang = cookie.get('lang_id');
            var endDate = "2019/05/23";
            if (params && params.endDate) {
                endDate = params.endDate;
            }

            div_obj.datepicker({
                rtl: false,
                format: _dateFormat,
                language: _lang,
                todayHighlight: true,
                endDate: endDate,
                startDate: -Infinity,
                calendarWeeks: true,
                autoclose: true
            });

            // 标记周
            div_obj.on('show', function() {
                // 添加一个class, 在鼠标滑动到一行时，高亮当前周
                $('.datepicker').addClass('week-datepicker');
            }).on('changeDate', setWeekRange)
                .on('hide', setWeekRange);

            var $ipt = $('input', div_obj).length ? $('input', div_obj) : div_obj;
            function setWeekRange() {
                var value = $ipt.val();
                var firstDate = moment(value).day(0).format("YYYY/MM/DD");
                var lastDate =  moment(value).day(6).format("YYYY/MM/DD");
                if(value.indexOf('-') > -1){
                    var arr = value.split(' - ') || [];
                    firstDate = moment(arr[0]).day(0).format("YYYY/MM/DD");
                    lastDate =  moment(arr[1]).day(6).format("YYYY/MM/DD");
                }
                setTimeout(function() {
                    $ipt.val(firstDate + " - " + lastDate);
                });
            }

            // 设置初始值
            var initDate = params && params.date || new Date();
            div_obj.datepicker('setDate', moment(initDate).format("YYYY/MM/DD"));
        },

        /*
        * 删除原有的datepicker以及绑定的事件
        */
        destroyDatePicker: function(ele){
            $(ele).off('click.daterangepicker focus.daterangepicker keyup.daterangepicker keydown.daterangepicker').datepicker('remove'); // 清除日期选择控件及事件
        },

        /*
        * 集中处理时间选择插件，支持：小时、天、周、月、年，如需选时间（时、分、秒），使用单独的插件（this.timePicker）
        * @params iptDom { String, Object } , input的选择器或者DOM对象、jquery对象；
        * @params type { String }, 类型："month"、"week"、"year"、"hour"、"custom"、"day",默认值："day".
        * 注：iptDom对应的DOM必须时input,不然切换datepicker、daterangepicker时DOM渲染出错，界面错位。
        * 原因是因为datepicker和daterangepicker共同支持input，如果不是input, 在daterangepicker渲染过程中会修改DOM，
        * 再次切换回datepicker会导致界面错位，功能失效。
        * 例如：
        *   <div class="input-group date date-picker">
        *       <span class="input-group-btn">
        *           <button class="btn default" type="button"><i class="fa fa-calendar"></i></button>
        *       </span>
        *       <input type="text" id="{{ DOM_ID }}" class="form-control" readonly>
        *   </div>
        * */

        commonPicker: function (obj) {
            if(!(obj && obj.iptDom)){
                // 必须有一个input的选择器或者DOM对象、jquery对象作为宿主
                return;
            }
            var _self = this,
                paramsObj = $.extend({}, obj),
                selectorId = $(obj.iptDom).get(0).id,
                type = paramsObj.type,
                _params = paramsObj.params;
            _self.destroyDatePicker(obj.iptDom);
            switch (type) {
                case 'month':
                    _self.monthPicker(selectorId, _params); break;
                case 'week':
                    _self.weekPicker2(selectorId, _params); break;
                case 'custom':
                    _self.Set(selectorId, _params); break;
                case 'year':
                    _self.yearPicker(selectorId, _params); break;
                case 'hour':
                    _self.Set(selectorId, $.extend({}, _params, {timePicker: 'hour'})); break;
                case 'minutes':
                    _self.Set(selectorId, $.extend({}, _params, {timePicker: 'minutes'})); break;
                case 'seconds':
                    _self.Set(selectorId, $.extend({}, _params, {timePicker: 'seconds'})); break;
                default:
                    _self.datePicker(selectorId, _params); break;
            }
        }
    },

    //日期函数
    Date: {
        /*
         * 日期字符串加上/减去指定天数
         * @dayCount 天数
         * @boolean  true正,false负
         * @author polar
         * */
        addDay: function (dateStr, dayCount, boolean) {
            var isDate = new Date(dateStr.replace(/-/g, "/"));
            var addDate = new Date((isDate / 1000 + (dayCount * 60 * 60 * 24)) * 1000);
            if (typeof boolean != "undefined" && boolean == false) {
                addDate = new Date((isDate / 1000 - (dayCount * 60 * 60 * 24)) * 1000);
            }
            var month = addDate.getMonth() + 1;
            var day = addDate.getDate();
            var result = addDate.getFullYear() + "/" + (month < 10 ? ("0" + month) : month) + "/" + (day < 10 ? ("0" + day) : day);
            return result;
        },

        //根据年月获取指定月份的天数
        getDaysOfMonth: function (year, month) {
            var isDate = new Date(year, month, 0);  //或者new Date(year,month-1,1)
            var days = isDate.getDate();
            return days;
        },
        //根据日期字符串获取当月结束时间
        getLastMonth: function (dateStr) {
            var date_arr = dateStr.split("/");
            var days = publicData.Date.getDaysOfMonth(date_arr[0], date_arr[1]);
            return date_arr[0] + "/" + date_arr[1] + "/" + days;
        },

        //获取给定日期的周一
        getMonday: function (dateStr) {
            var isDate = new Date(dateStr.replace(/-/g, "/"));
            var numDay = isDate.getDay();
            numDay = (numDay != 0) ? (numDay - 1) : 6;
            var monday = this.addDay(dateStr, numDay, false);
            return monday;
        },

        /*
         * 获取最近n天的日期
         * @days  n天
         * */
        getLastdays: function (days) {
            if (typeof days == "undefined") {
                days = 7;
            }
            var now = new Date().getTime();
            var start_date = new Date(now - 24 * 60 * 60 * 1000 * days);
            start_date = start_date.getFullYear() + "/" + getDigtalNumber(start_date.getMonth() + 1) + "/" + getDigtalNumber(start_date.getDate());

            function getDigtalNumber(num){
                return Number(num)/10 >= 1 ? (num+'') : ('0'+num);
            }
            return start_date;
        },


        /*
         * 取当前时间5的整数倍
         * @hours  n小时,默认最近2小时
         * */
        getIntegerMinutes: function (hours) {
            if (typeof hours == "undefined") {
                hours = 2;
            }
            var now_date = new Date();
            var now_m = now_date.getMinutes();
            var max_minute = now_m - now_m % 5;
            var start_date = new Date(now_date.getTime() - hours * 60 * 60 * 1000);
            start_date = start_date.getFullYear() + "/" + (start_date.getMonth() + 1) + "/" + start_date.getDate() + " " + start_date.getHours() + ":" + max_minute + ":00";
            //var end_date = now_date.getFullYear() + "/" + (now_date.getMonth() + 1) + "/" + now_date.getDate() + " " + now_date.getHours() + ":" + max_minute + ":00";
            //return new Array(start_date, end_date);
            return start_date;
        },

        /*
         * 时长转换
         * 时分秒
         * length:时长
         * type:类型(默认秒sec)
         * */
        transformTime: function (length, type) {
            var hour = Math.floor(length / 3600);
            var min = Math.floor(length / 60) % 60;
            var sec = length % 60;
            var time = '';
            if (hour > 0) {
                time = hour + "小时" + min + "分" + sec + "秒";
            } else if (min > 0) {
                time = min + "分" + sec + "秒";
            } else {
                time = sec + "秒";
            }
            return time;
        }
    },

    //获取当前用户平台ID列表
    Platfrom_Id: {
        _PFID: [], //所有元素
        _NPFID: [], //所有元素

        //多选
        Multi: function (_dom, _callback) {
            var ajaxStr = [];
            var self = this;
            ajaxStr.async = false;
            ajaxStr.url = "nn_api/nn_dispatch.php?func=get_platform_role";
            ajaxStr.post_json = {};
            ajaxStr.success = function (result) {
                //成功回调
                self._PFID = [];
                if (result.data.length != 0) {
                    var data = result.data;
                    var _html = '';
                    for (var i = 0; i < data.length; i++) {
                        self._PFID.push(data[i]);
                        _html += '<option value="' + data[i].platform_id + '">' + data[i].platform_name + '</option>';
                    }
                }
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.error = function (result) {
                //失败回调
                var _html = '<option value=""></option>';
                _dom.html(_html).selectpicker('refresh');
            };
            ajaxStr.nodata = function (result) {
                //接口无数据
                var _html = '<option value=""></option>';
                _dom.html(_html).selectpicker('refresh');
            };

            STD.TOOL.ajaxNoPlatform(ajaxStr);
        },

        //单选
        Select: function (_dom, _callback) {
            //TODO
        },

        GetPlatformId: function (_dom) {

            //判断是否有参数传递,有参数则表示为获取并为DOM节点元素赋值，无则为只获取
            var n_platform_id = '';
            if (_dom) {
                n_platform_id = _dom.selectpicker('val');
            }
            else {
                n_platform_id = null;
            }
            //返回请求数据,格式为string;
            if ((n_platform_id !== '') && (n_platform_id !== null)) {
                return n_platform_id.join(",");
            }
            else {
                var platformId = '';
                var ajaxStr = [];
                var self = this;
                ajaxStr.async = false;
                ajaxStr.url = "nn_api/nn_dispatch.php?func=get_platform_role";
                ajaxStr.post_json = {};
                ajaxStr.success = function (result) {
                    //成功回调
                    self._NPFID = [];
                    if (result.data.length != 0) {
                        var data = result.data;
                        var _html = [];
                        for (var i = 0; i < data.length; i++) {
                            self._NPFID.push(data[i]);
                            _html.push(data[i].platform_id)
                        }
                    }
                    platformId = _html.join(",");
                };
                ajaxStr.error = function (result) {
                    //失败回调
                    platformId = '';

                };
                ajaxStr.nodata = function (result) {
                    //接口无数据
                    platformId = '';

                };
                $.ajax(ajaxStr);
                return platformId;
            }

        }

    },

    //工具函数
    Tools: {
        /*
         * 将一个数分配X份，每份随机，类似微信抢红包
         * @totalAmount 总大小
         * @totalAmount 份数
         * */
        assign: function (totalAmount, totalPeople) {
            var self = this;
            var remainAmount = totalAmount;
            var remainPeople = totalPeople;
            var arr = [];
            while (remainPeople > 0) {
                let num = self.scramble(remainAmount, remainPeople);
                remainAmount = remainAmount - num;
                remainPeople--;
                arr.push(num);
            }
            return arr;

        },

        /**/
        scramble: function (remainAmount, remainPeople) {
            if (remainPeople === 1) {
                return +remainAmount.toFixed(2);
            }
            let max = ((remainAmount / remainPeople) * 2 - 1).toFixed(2);
            let min = 1;
            let range = max - min;
            let rand = Math.random();
            let num = min + Math.round(rand * range); //四舍五入
            return num;
        }
    }
};


/*
 * 扩展String方法
 * 替换占位符
 * @args {name:"Cathy",age:22}
 * @args "Cathy","22"
 * @author polar
 * */
String.prototype.format = function (args) {
    var result = this;
    if (arguments.length > 0) {
        if (arguments.length == 1 && typeof (args) == "object") {
            //字符串的key与args的key一一对应

            for (var key in args) {
                if (args[key] != undefined) {
                    var reg = new RegExp("({" + key + "})", "g");
                    result = result.replace(reg, args[key]);
                }
            }
        } else {
            //字符串中为{0},{1}的数字,args可按顺序传值

            for (var i = 0; i < arguments.length; i++) {
                if (arguments[i] != undefined) {
                    //var reg = new RegExp("({[" + i + "]})", "g");//这个在索引大于9时会有问题
                    var reg = new RegExp("({)" + i + "(})", "g");
                    result = result.replace(reg, arguments[i]);
                }
            }
        }
    }
    return result;
};

/*
 * 扩展jQuery方法
 * @author polar
 * */
$.extend({
    /*
     * 判断是否是空对象
     * */
    isEmptyObject: function (obj) {
        for (var key in obj) {
            return false;
        }
        return true;
    }
});

/*
 * 扩展Date方法
 * @author polar
 * 获取季度
 * */
Date.prototype.getQuarter = function () {
    var month = this.getMonth();
    if (month < 3) {
        return "1";
    } else if (month < 6) {
        return "2";
    } else if (month < 9) {
        return "3";
    } else if (month < 12) {
        return "4";
    }
};